extensions/gggl{,-lies}.c: fix conversions u16 <-> u8
authorMassimo Valentini <mvalentini@src.gnome.org>
Sat, 14 Jul 2012 15:07:38 +0000 (17:07 +0200)
committerMassimo Valentini <mvalentini@src.gnome.org>
Sat, 14 Jul 2012 15:07:38 +0000 (17:07 +0200)
commit07cc0809228236c7fdcab6b61c4d515f9b93dc84
tree60d8518b9f9352d5500bb639a3b0da84d2bc804f
parentae222ac5a86cafea4aeb018209bfa384fdc97970
extensions/gggl{,-lies}.c: fix conversions u16 <-> u8

u16 maximum value is 0x10000 - 1 == (0x100 - 1) (0x100 + 1)
u8 maximum value is 0x100 - 1
thus the direct conversion requires multiplication/division per
0x100+1

division per 0x100+1 is implemented using 1 term of (1 + x)^-1
MacLaurin expansion

(1+x)^-1 == 1 + (-1) x

a * (1 + 1/256)^-1 * (256^-1) == (a - a / 256) / 256

with integer division rounded toward the nearest.
extensions/gggl-lies.c
extensions/gggl.c